<!DOCTYPE html>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>EMQ测试</title>

<script src="mqttws31.min.js"></script>
<script>
const console_log = console.log;
console.log = function(message) {
    console_log.apply(this, arguments);
    document.write(message + "<br />");
};


const hostname = 'vps.firadio.net';
const port = 8083;
// Create a client instance
const client = new Paho.MQTT.Client(hostname, Number(port), "clientId");

// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;

// connect the client
client.connect({onSuccess:onConnect});


// called when the client connects
function onConnect() {
  // Once a connection has been made, make a subscription and send a message.
  console.log("onConnect");
  client.subscribe("testtopic/1");
  /*
  message = new Paho.MQTT.Message("Hello");
  message.destinationName = "World";
  client.send(message);
  */
}

// called when the client loses its connection
function onConnectionLost(responseObject) {
  if (responseObject.errorCode !== 0) {
    console.log("onConnectionLost:"+responseObject.errorMessage);
  }
}

// called when a message arrives
function onMessageArrived(message) {
  console.log("onMessageArrived:"+message.payloadString);
}
</script>